package cn.siat.gene.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.siat.common.core.domain.R;
import cn.siat.common.core.exception.ServiceException;
import cn.siat.common.core.web.controller.BaseController;
import cn.siat.common.core.web.domain.AjaxResult;
import cn.siat.common.core.web.page.TableDataInfo;
import cn.siat.common.log.annotation.Log;
import cn.siat.common.log.enums.BusinessType;
import cn.siat.common.security.utils.SecurityUtils;
import cn.siat.gene.domain.DesignTBExternalPaccout;
import cn.siat.gene.domain.vo.DesignTBExternalPaccoutVo;
import cn.siat.gene.service.DesignService;
import cn.siat.gene.service.DesignTBExternalPaccoutService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author yangmw
 * @create 2022-11-21 15:07
 */
@RestController
@RequestMapping("external/paccout")
@Slf4j
public class DesignTBExternalPaccoutController extends BaseController {
    @Autowired
    private DesignTBExternalPaccoutService designTBExternalPaccoutService;

    /**
     * 列表查询
     */
    @GetMapping("/list")
    public TableDataInfo listExternalPaccout(DesignTBExternalPaccout designTBExternalPaccout)
    {
        startPage();
        List<DesignTBExternalPaccoutVo> list = designTBExternalPaccoutService.selectDesignTBExternalPaccoutList(designTBExternalPaccout);
        return getDataTable(list);
    }
    /*
     * 新增关联账户
     */
    @Log(title = "新增关联账户", businessType = BusinessType.OTHER)
    @PostMapping("/add")
    public AjaxResult saveExternalPaccout(@RequestBody DesignTBExternalPaccout designTBExternalPaccout){
        return AjaxResult.success(designTBExternalPaccoutService.insertDesignTBExternalPaccout(designTBExternalPaccout));
    }
    /*
     * 解绑
     */
    @Log(title = "账户解绑", businessType = BusinessType.OTHER)
    @PutMapping("/unbind/{id}")
    public AjaxResult unBind(@PathVariable String id){
        return AjaxResult.success(designTBExternalPaccoutService.unBindDesignTBExternalPaccout(id));
    }
    /*
     * 绑定
     */
    @Log(title = "账户绑定", businessType = BusinessType.OTHER)
    @PutMapping("/bind/{id}")
    public AjaxResult bind(@PathVariable String id){
        return AjaxResult.success(designTBExternalPaccoutService.bindDesignTBExternalPaccout(id));
    }
    /*
     * 删除
     */
    @Log(title = "删除关联账户", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteExternalPaccout(@PathVariable String id){
        return AjaxResult.success(designTBExternalPaccoutService.removeExternalPaccout(id));
    }
    /**
     * 编辑账户
     */
    @PutMapping("/edit")
    public AjaxResult editExternalPaccout(@RequestBody DesignTBExternalPaccout designTBExternalPaccout)
    {
        return AjaxResult.success(designTBExternalPaccoutService.updateExternalPaccout(designTBExternalPaccout));
    }
    /**
     * 是否绑定元件库账户
     */
    @GetMapping("/hasBindComponent")
    public AjaxResult hasBindComponent()
    {
        return AjaxResult.success(designTBExternalPaccoutService.hasBindComponent());
    }

    /**
     * 是否绑定装置设计
     */
    @GetMapping("/hasBindDesign")
    public AjaxResult hasBindDesign()
    {
        return AjaxResult.success(designTBExternalPaccoutService.hasBindDesign());
    }

    /**
     * 是否绑定基础数据库
     */
    @GetMapping("/hasBindGenePool")
    public AjaxResult hasBindGenePool()
    {
        return AjaxResult.success(designTBExternalPaccoutService.hasBindGenePool());
    }


    /**
     *  验证账号
     * @return
     */
    @PostMapping ("/verifyToken")
    public AjaxResult verifyToken(@RequestBody Map<String,String> map){
        String username = map.get("username");
        String password = map.get("password");
        String system = map.get("system");
        AjaxResult result = designTBExternalPaccoutService.verifyToken(username, password, system);
        return result;
    }
}
